import { getList, knowledgeClassification, addLabel, deleteLabel,labelInfo,updateLabel,upOrDown,getShareKnowledges } from '@/services/hotPoint';

export default {
  namespace: 'leftMenu',
  state: {
    total: 0,
    items: [],
    loading: true
  },
  effects: {
    *getList({ payload, callback }, { call, put }) {
      const response = yield call(getList, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getKnowledge({ payload, callback }, { call, put }) {
      const response = yield call(getShareKnowledges, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *addLabel({ payload, callback }, { call, put }) {
      const response = yield call(addLabel, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *deleteLabel({ payload, callback }, { call, put }) {
      const response = yield call(deleteLabel, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *labelInfo({ payload, callback }, { call, put }) {
      const response = yield call(labelInfo, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *updateLabel({ payload, callback }, { call, put }) {
      const response = yield call(updateLabel, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *upOrDown({ payload, callback }, { call, put }) {
      const response = yield call(upOrDown, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
